package org.example;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;

public class Collections_Demo1 {
    public static void main(String[] args) {
        ArrayList<String> list=new ArrayList<>();
        //批量添加
        Collections.addAll(list, "A", "B", "C", "D", "E", "F", "G");
        System.out.println(list);
        //打乱数据 随机获取1 打乱了数据可直接获取索引0
        Collections.shuffle(list);
        System.out.println(list.get(0));
        System.out.println("------------------1");
        //随机方法2
        Random rand = new Random();
        int index = rand.nextInt(list.size());
        System.out.println(list.get(index));

    }
}
